package com.ning.cloud.order.controller;

import com.ning.cloud.common.util.Response;
import com.ning.cloud.user.api.client.UserClient;
import com.ning.cloud.user.api.dto.UserDTO;
import com.ning.cloud.user.api.dto.UserRegisterDTO;
import com.ning.cloud.user.api.request.UserRegisterRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * 订单
 */
@RestController
@RequestMapping("/order")
@Slf4j
@Tag(name = "订单管理模块")
public class OrderController {

    @Resource
    UserClient userClient;

    @GetMapping("/user")
    @Operation(summary = "查询用户信息")
    public Response<UserDTO> info(){
        Response<UserDTO> result = userClient.getUserById(1L);
        if (!result.getCode().equals(0)){
            return Response.error(result.getCode(),result.getMessage());
        }
        return Response.success(result.getData());
    }

    @PostMapping("/user/register")
    @Operation(summary = "用户注册")
    public Response<UserRegisterDTO> register(@RequestBody @Valid UserRegisterRequest userRegisterRequest){
        Response<UserRegisterDTO> result = userClient.register(userRegisterRequest);
        if (!result.getCode().equals(0)){
            return Response.error(result.getCode(),result.getMessage());
        }
        return Response.success(result.getData());
    }


}
